module(..., package.seeall)

local Player = require "player"
local tiled = require "tiled"

--------------------------------------------------------------------------------
-- Event Handler
--------------------------------------------------------------------------------

function onCreate(e)
    tileLayer = flower.Layer()
    tileLayer:setScene(scene)
    tileLayer:setSortMode(MOAILayer.SORT_PRIORITY_ASCENDING)

    tileMap = tiled.TileMap()
    tileMap:loadLueFile("../assets/maps/testmap.lua")
    tileMap:setLayer(tileLayer)

    player = Player(tileMap)
    playerLayer = flower.Layer()
    playerLayer:setScene(scene)
    player:setLayer(playerLayer)

    tileMap:removeMapLayer(tileMap:findMapLayerByName("pLayer"))

    flower.Executors.callLoop(function() player:update() end)
end

function onClose(e)
	player:destroy()
	tileMap:destroy()
end
